#ifndef MEMORY_H
#define MEMORY_H

// Size of one page in bytes and number of page entries in a page table.
#define PG_SIZE		0x1000
#define PG_NUM		0x400

// Page table entry and page directory entry flags.
#define PG_PRESENT	0x1
#define PG_RW		0x2
#define PG_USER		0x4

// The kernel is linked tp the virtual address KERNBASE.
// KERN_V2P translates virtual addresses of the kernel to physical addresses.
#define KERNBASE 	0xF0000000
#define KERN_V2P(x)	((x) - KERNBASE)

// Kernel stack size.
#define KSTACKSIZE	(8*PG_SIZE)

// Round down and up to page boundary.
#define PG_ROUND_DOWN(x)	((x) & 0xFFFFF000)
#define PG_ROUND_UP(x)		((x) | 0x00000FFF)

// Get PDE and PTE from linear address.
#define LIN2PDE(x)	((x)>>22)
#define LIN2PTE(x)	(((x)>>12) & 0x3FF)

// Gets VA of the PTE containing VA x. Works because the last PDE

#ifndef __ASSEMBLER__

typedef struct {
	uint32_t	*addr;
	uint32_t	count;
} page_t;

extern uint32_t *kern_end;

#endif	// __ASSEMBLER__

#endif	// MEMORY_H